Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

188
Views
How can I make the output of a js not on one single line? How can the output "fit" the input box?

This is the js code I have written. It generate a random string. I have set this string to be 100 characters long but it doesnt "fit" the input box. The string is just shown on one line.

<div>
  <script>
    var password = document.getElementById("password");
    function genPassword() {
      var chars =
        "0123456789abcdefghijklmnopqrstuvwxyz!@#$%^&*()ABCDEFGHIJKLMNOPQRSTUVWXYZ";
      var passwordLength = 100;
      var password = "";
      for (var i = 0; i <= passwordLength; i++) {
        var randomNumber = Math.floor(Math.random() * chars.length);
        password += chars.substring(randomNumber, randomNumber + 1);
      }
      document.getElementById("password").value = password;
    }
    function copyPassword() {
      var copyText = document.getElementById("password");
      copyText.select();
      copyText.setSelectionRange(0, 999);
      document.execCommand("copy");
    }
  </script>
  <div class="konzbox">
    <h2>Zufälliger Konztest-Generator</h2>
    <input
      type="text"
      name=""
      placeholder="Erstelle Konztest"
      id="password"
      readonly
    />
    <table>
      <th>
        <div id="button" class="btn1" onclick="genPassword()">Generate</div>
      </th>
      <th>
        <div id="button" class="btn2" onclick="copyPassword()">Copy</div>
      </th>
    </table>
  </div>
</div>

You see here that not all of the output can be seen

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can use a textarea instead of input for your password.

function genPassword() {
   var chars = "0123456789abcdefghijklmnopqrstuvwxyz!@#$%^&*()ABCDEFGHIJKLMNOPQRSTUVWXYZ";
   var passwordLength = 100;
   var password = "";
   for (var i = 0; i <= passwordLength; i++) {
      var randomNumber = Math.floor(Math.random() * chars.length);
      password += chars.substring(randomNumber, randomNumber +1);
    }
        document.getElementById("password").value = password;

    }
  function copyPassword() {
  var copyText = document.getElementById("password");
  copyText.select();
  copyText.setSelectionRange(0, 999);
  document.execCommand("copy");
  }
<div class="konzbox">
  <h2>Zufälliger Konztest-Generator</h2>
  <textarea name="" id="password" cols="30" rows="10" readonly></textarea>
  <table>
    <th><div id="button" class="btn1" onclick="genPassword()">Generate</div></th>
    <th><div  id="button" class="btn2" onclick="copyPassword()">Copy</div></th>
  </table>
</div>

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!